\subsection{Arrays of arrays}\label{array.07}

\textbf{Concept} A two-dimensional array is really an array of arrays; that is, each 
element of the array contains a reference to another array. Therefore, by
using only one index a one-dimensional array is obtained.

\prg{Array07}
\prgl{array}{Array07}

This program creates a $2 \times 2$ matrix and then assigns the second row to a variable of type \emph{one-dimensional} array.
\begin{itemize}
  \item A two-dimensional array is allocated, the reference to it is assigned to the variable \texttt{matrix}.
  The variable \texttt{matrix} contains one reference for each row and the rows are allocated as separate objects. Note that \jel{} displays rows from top to bottom as it does for all objects!
  \item The elements of the array are initialized to (0,1,2,3) in a nested for-loop.
  The outside loop iterates over the rows and the inner loop iterates over the
  columns within an array.
  \item \texttt{matrix.length} is used to get the number of rows and 
  \texttt{matrix[i].length} to get the number of columns in row \texttt{i}, which 
  is the same for all rows in this program.
  \item A variable \texttt{vector} of type one-dimensional array is declared and initialized
  with the second row of the matrix, \texttt{matrix[1]}.
  \end{itemize}

\textbf{Exercise} Write a program to rotate the rows of the array \texttt{matrix}. That is, row 0 becomes row 1 and row 1 becomes row 0. Now do this for an array of size $3 \times 3$: row 0 becomes row 1, row 1 becomes row 2 and row 2 becomes row 0.
